from optparse import OptionParser
import os
    
if __name__ == "__main__":
	parser = OptionParser()
	parser.add_option("-n", "--nhost", dest = "nhost", help = "number of hosts")
	parser.add_option("--wan_bw", dest = "wan_bw", help = "the bandwidth of wan link(G)", default = "10")
	parser.add_option("--dcn_bw", dest = "dcn_bw", help = "the bandwidth of dcn link(G)", default = "10")
	parser.add_option("--tor_bw", dest = "tor_bw", help = "the bandwidth of tor link(G)", default = "10")
	parser.add_option("--wan_delay", dest = "wan_delay", help = "delay of wan(ns)", default = "1000000")
	parser.add_option("--dcn_delay", dest = "dcn_delay", help = "delay of dcn(ns)", default = "1000")
	parser.add_option("-o", "--output", dest = "output", help = "output file name", default = "cdc_topo.txt")
	parser.add_option("--wan_error", dest = "wan_error", help = "error rate of wan", default = "0.000000")
	parser.add_option("--dcn_error", dest = "dcn_error", help = "error rate of dcn", default = "0.000000")
	options,args = parser.parse_args()

	nhost = int(options.nhost)
	dcn_bw = options.dcn_bw + "Gbps"
	wan_bw = options.wan_bw + "Gbps"
	tor_bw = options.tor_bw + "Gbps"
	dcn_delay = options.dcn_delay + "ns"
	wan_delay = options.wan_delay + "ns"
	dcn_error = options.dcn_error
	wan_error = options.wan_error
	output_file = os.path.join("..", "input", options.output)

	links = [
		[nhost + 6, 6, nhost + 5],
		[nhost, nhost + 1, nhost + 2, nhost +3, nhost + 4, nhost + 5]
	]

	tor = int(nhost / 4)
	for i in range(0, tor):
		links.append([i, nhost, dcn_bw, dcn_delay, dcn_error])
	for i in range(tor, 2 * tor):
		links.append([i, nhost + 1, dcn_bw, dcn_delay, dcn_error])
	for i in range(2 * tor, 3 * tor):
		links.append([i, nhost + 2, dcn_bw, dcn_delay, dcn_error])
	for i in range(3 * tor, 4 * tor):
		links.append([i, nhost + 3, dcn_bw, dcn_delay, dcn_error])

	links.append([nhost + 0, nhost + 4, tor_bw, dcn_delay, dcn_error])
	links.append([nhost + 1, nhost + 4, tor_bw, dcn_delay, dcn_error])
	links.append([nhost + 2, nhost + 5, tor_bw, dcn_delay, dcn_error])
	links.append([nhost + 3, nhost + 5, tor_bw, dcn_delay, dcn_error])
	links.append([nhost + 4, nhost + 5, wan_bw, wan_delay, wan_error])

with open(output_file, "w") as f:
    for link in links:
        f.write(" ".join(map(str, link)) + "\n")

print(output_file)